package com.example.zhou.filehelper;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 11065 on 2016/11/10.
 */

public class FileHelper {

    private static File fileroot;
    List<String> list = new ArrayList<>();

    private File getFileRoot() {
        return android.os.Environment.getExternalStorageDirectory();
    }

    private File[] getFileArray(File file) {
        if (file.isDirectory()) {
            return file.getAbsoluteFile().listFiles();
        }
        return null;
    }

    public List<String> getMp3() {
        return getFile(getFileArray(getFileRoot()));
    }

    private List<String> getFile(File[] file) {

        if (file != null)
            for (File aFile : file) {
                if (aFile.isDirectory()) {
                    File[] file1 = aFile.listFiles();
                    getFile(file1);
                } else if (aFile.isFile() && aFile.getName().endsWith(".mp3") && aFile.length() > 2 * 1024 * 1024) {
                    list.add(aFile.getAbsolutePath());
                }
            }
        Log.e("list", list.size() + "");
        return list;
    }


//    private File getFile() {
//        if (getFileArray() != null)
//            for (int i = 0; i < getFileArray().length; i++) {
//
//            }
//    }
}
